!# WIBIOS 0.1
!# Copyright Matthew F. Rienzo, 2014

[HEADER]
  .bits 32
  .end
[VARS]
  *__##BIOS##__VERSION       0.1
  *__##BIOS##__AUTHOR        Matthew F. Rienzo
  *__##BIOS##__PROC_ARCH     WI100
  *__##BIOS##__PROC_GEN      WI10x
  *NULL             0
  .end
[CODE]
  !# Copyright Matthew F. Rienzo, 2014
  
  ! int 0x10
  .__##BIOS##__print_to_cli:
    
    pop0x10 %a0
	
    _sl_
	  print $regs->{a0};
    _end_
	
	free %a0
	
    ret
    .stop

  ! int 0x11
  
  .__##BIOS##__println_to_cli:
    pop0x11 %a0
    _sl_
      print $regs->{a0}."\n";
    _end_
    free %a0
	ret
    .stop

  ! int 0x12
  .__##BIOS##__proc_info_arch:
    movv %s0 *__##BIOS##__PROC_ARCH
	
	push0x12 %s0
	
	ret
	.stop
	
  ! int 0x13
  .__##BIOS##__version:
    movv %s0 *__##BIOS##__VERSION
	
	push0x13 %s0
	
	ret
	.stop
	
  ! int 0x14
  .__##BIOS##__proc_gen:
    movv %s0 *__##BIOS##__PROC_GEN

    push0x14 %s0

    ret
    .stop
	
  ! int 0x15
  .__##BIOS##__setCursorPosition:
    ! in : x= a0, y = a1
	pop0x15 %a0
	pop0x15 %a1
	
	_sl_
	$__VM_HT->{__VM_Registry}->{__vmX} = $regs->{a0};
	$__VM_HT->{__VM_Registry}->{__vmY} = $regs->{a1};
	_end_
	
    free %a0
	free %a1
	ret
	.stop
	
  ! int 0x16
  .__##BIOS##__setColor:
    ! in : color=%a0
	pop0x16 %a0
	
	_sl_
	$__VM_HT->{__VM_Registry}->{__color} = $regs->{a0};
	_end_
	
	free %a0
	ret
	.stop
	
  ! int 0x17
  .__##BIOS##__setFontSize:
    ! in : size = a0
	pop0x17 %a0
	
	_sl_
	$__VM_HT->{__VM_Registry}->{__fonsize} = $regs->{a0};
	_end_
	
	free %a0
	ret
	.stop
	
  ! int 0x18
  .__##BIOS##__print:
    ! 80x25...
	! 800x600px screen...
	! 800/80 = 10.  So 10 px length
	! 600/25 = 24.  So 24px height
	pop0x18 %a0
	
	_sl_
	  my $msg = SDLx::Text->new(
	  x => $__VM_HT->{__VM_Registry}->{__vmX},
		  y => $__VM_HT->{__VM_Registry}->{__vmY},
		  color => $__VM_HT->{__VM_Registry}->{__color},
		  size => $__VM_HT->{__VM_Registry}->{__fontsize},
		  font => "BIOS_IMAGE/FSEX300.TTF",
		);
		
		$msg->write_to($__VM_SDL_SCREEN, $regs->{a0});
		$__VM_SDL_SCREEN->update();
		
	 $__VM_HT->{__VM_Registry}->{__vmY} += 19;
	  _end_
		
	  ret 
	  .stop

  ! int 0x19
  .__##BIOS##__putchar:
    ! putchar(%a0)
	
	pop0x19 %a0
	
	_sl_
	$regs->{f0} = $__VM_HT->{__VM_Registry}->{__vmX} / 12;
	$regs->{f1} = $__VM_HT->{__VM_Registry}->{__vmY} / 19;
	_end_
	
	loadi %f2 69
	loadi %f3 31
	
	cmp %f2 %f0
	  loadi %f0 0
	  loadi %f4 1
	  add %f1 %f1 %f4
	scmp
	
	cmp %f1 %f3
	  loadi %f1 0
	  loadi %f0 0
	scmp
	
	_sl_
	$__VM_HT->{__VM_Registry}->{__vmX} = $regs->{f0} * 12;
	$__VM_HT->{__VM_Registry}->{__vmY} = $regs->{f1} * 19;
	
	if ($regs->{a0} eq "\n"){
	  $__VM_HT->{__VM_Registry}->{__vmY} += 19;
	  $__VM_HT->{__VM_Registry}->{__vmX} = 0;
	  
	_end_
	ret
	_sl_
	}
	
	my $msg = SDLx::Text->new(
	  x => $__VM_HT->{__VM_Registry}->{__vmX},
		  y => $__VM_HT->{__VM_Registry}->{__vmY},
		  color => $__VM_HT->{__VM_Registry}->{__color},
		  size => $__VM_HT->{__VM_Registry}->{__fontsize},
		  font => "BIOS_IMAGE/FSEX300.TTF",
		);
		
		$msg->write_to($__VM_SDL_SCREEN, $regs->{a0});
		$__VM_SDL_SCREEN->update();
		
	 $__VM_HT->{__VM_Registry}->{__vmX} += 12;
	_end_
	
	free %f0
	free %f1
	free %f2
	free %f3
	free %f4
	
	ret
	.stop
	
  ! int 0x1a
  .__##BIOS##__puts:
    ! puts(%a0)
	
	pop0x1a %a0
	
	_sl_
	my @chars = split '', $regs->{a0};
	
	for my $index (0..$#chars){
	  $regs->{a0} = $chars[$index];
	_end_
	
	push0x19 %a0
	call __##BIOS##__putchar
	
	_sl_
	}
	_end_
	
	free %a0
	ret
	.stop
	
  .IRQ_MAP:
    set __##BIOS##__print_to_cli                              0x10
	set __##BIOS##__println_to_cli                            0x11
	set __##BIOS##__proc_info_arch                            0x12
	set __##BIOS##__version                                   0x13
	set __##BIOS##__proc_gen                                  0x14
	set __##BIOS##__setCursorPosition                         0x15
	set __##BIOS##__setColor                                  0x16
	set __##BIOS##__setFontSize                               0x17
	set __##BIOS##__print                                     0x18
	set __##BIOS##__putchar                                   0x19
	set __##BIOS##__puts                                      0x1a
	
	.stop
	
  .__##BIOS##__main:
    ! VMAI interrupt 0x06 clears the screen to a black screen
	! This will be replaced with a BIOS function though....in the future
	int 0x06
	
	! proc_info_arch
	! proc_gen
	! version
	movv %r0 *__##BIOS##__PROC_ARCH
	movv %r1 *__##BIOS##__PROC_GEN
	movv %r2 *__##BIOS##__VERSION
	
    loadi %a0 14
	
	! setFontSize
	push0x17 %a0
	int 0x17
	
	loadi %a0 0
	loadi %a1 0
	
	! setCursorPosition
	push0x15 %a0
	push0x15 %a1
	int 0x15
	
	loadd %a0 "WIBIOS 0.1 Copyright (C) Matthew F. Rienzo, 2014\n"
	
	! print
	push0x1a %a0
	int 0x1a
		
	loadd %a0 "Processor architecture: "
	appr %a0 %r0
	app %a0 "\n"
	
	! print
	push0x1a %a0
	int 0x1a
	
	loadd %a0 "Processor generation: "
	appr %a0 %r1
	app %a0 "\n"
	
	push0x1a %a0
	int 0x1a
	
	loadd %a0 "+------------------------------------------------+\n"
	app %a0   "| This software is distributed with VMAI/N03.\x20\x20 \x20|\n"
	app %a0   "| Open source, Copyright Matthew F. Rienzo, 2014 |\n"
	app %a0   "+------------------------------------------------+\n"
	
	push0x1a %a0
	int 0x1a
	
	! Pauses for 10 seconds
	loadi %a0 10
	
	push0x09 %a0
	int 0x09
	
	! Halts the machine if we're in the right ring mode...
	int 0x00
	ret
	.stop

  .testScreen:
    ! testScreen(void) -- for me, the developer, to find how big our screen is...................................
	
	! 11px long...19px tall at size 
	!69x with 31y...
	int 0x06
	
	loadi %a0 14
	
	push0x17 %a0
	int 0x17
	
	loadi %f0 0
	loadi %f2 30
	
	_sl_
	  while ($regs->{f0} ne $regs->{f2}){
	_end_
	
	loadd %a0 "00000000000000000000000000000000000000000000000000000000000000000x"
	  
	push0x18 %a0
	int 0x18
	
    _sl_
	$regs->{f0} += 1;
	}
	_end_
	
	loadd %a0 "x0000000000000000000000000000000000000000000000000000000000000000x"
	  
	push0x18 %a0
	int 0x18
	
	
	mov %a0 %f0
	
	free %f0
	free %f2
	
	push0x11 %a0
	int 0x11
	
	!loadi %a0 5
	!push0x09 %a0
	!int 0x09
	
	ret
	.stop
	
  .__entry:
	call testScreen
	
    call __##BIOS##__main
	.stop
  .end